*--------------------------------------------------------------; * Combined ratio estimate of the mean and total for a single- ; * stage cluster sample combined with stratification. ; *--------------------------------------------------------------; %macro e_cl1str(sample=,setup=,npop=,n=,strata=,cluster=, response=,mi=,param=,m=,mbar=); %if %length(&strata) = 0 %then %let strata = %str(strata); %if %length(&setup) = 0 %then %let setup = %str(setup); %if %length(&npop) = 0 %then %let npop = %str(npop); %if %length(&sample) = 0 %then %let sample = %str(sample); %if %length(&m) > 0 %then %let mbar = %str(&m/&npop); %if %length(&m) = 0 & %length(&mbar) = 0 %then %let mbar = %str(ave_m_); proc sort data = &setup; by &strata; proc sort data = &sample; by &strata; data est_; set &sample( keep = &mi &response &strata); my_ = &mi*&response; proc means data = est_ noprint; by &strata; var &mi &response my_; output out = cmb_out_ mean = ave_m_ ybari_ n = n1_ n2_ ni_ sum = summi_ sumyi_ summyi_ css = ssmmi_ ssyyi_; data cmb_out_; merge cmb_out_ &setup; by &strata; yy_ = &npop*ybari_; mm_ = &npop*ave_m_; mu_temp_ = &npop*&mbar; ssmyi_ = summyi_ - summi_*sumyi_/ni_; proc means data = cmb_out_ noprint; var mm_ yy_ mu_temp_ &npop; output out = combr_ sum = totm_ toty_ tu_m_ ntotal_; data combr_; set combr_; mu_mpop_ = tu_m_/ntotal_; rc_ = toty_/totm_; mu_hat_ = rc_*mu_mpop_; tau_hat_ = mu_hat_*ntotal_; data final_; if _n_ = 1 then set combr_; set cmb_out_; fpc_ = (&npop - ni_)/&npop; sr2_ = (ssyyi_ + rc_**2*ssmmi_ -2*rc_*ssmyi_)/(ni_-1); vterm_ = &npop**2*fpc_/ni_*sr2_; proc means data = final_ noprint; var vterm_ &npop; output out = est_cr_ sum = vnumer_ ntotal_; data est_cr_; merge est_cr_ combr_; var_tau_ = vnumer_; std_tau_ = sqrt(var_tau_); bnd_tau_ = 2*std_tau_; std_mu_ = std_tau_/ntotal_; bnd_mu_ = 2*std_mu_; std_r_ = std_tau_/(mu_mpop_*ntotal_); bnd_r_ = 2*std_r_; drop vnumer_; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_cr_ noobs split='*'; title1 "Combined Ratio Estimate of Population Total"; title2 "Single-stage Cluster Design with Stratification"; title3 "Response Variable = &response"; title4 "(Auxiliary Variable = Cluster Size)"; label tau_hat_ = 'Estimate'; label std_tau_ = 'Standard*Error'; label bnd_tau_ = 'Bound'; var tau_hat_ std_tau_ bnd_tau_; %end; %if %index(%upcase(¶m),MEAN) > 0 %then %do; proc print data = est_cr_ noobs split='*'; title1 "Combined Ratio Estimate of Population Mean"; title2 "Single-stage Cluster Design with Stratification"; title3 "Response Variable = &response"; title4 "(Auxiliary Variable = Cluster Size)"; label rc_ = 'Estimate'; label std_r_ = 'Standard*Error'; label bnd_r_ = 'Bound'; var rc_ std_r_ bnd_r_; %end; run; title; %mend e_cl1str;